package com.weixin.paleituo.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.adapter.SelectCityRecyclewAdapter;
import com.weixin.paleituo.base.BaseActivity;
import com.weixin.paleituo.bean.CityBean;
import com.weixin.paleituo.eventbus.SelectHouseEvent;
import com.weixin.paleituo.util.UIUtils;
import com.weixin.paleituo.view.RecyclerViewCityDecoration;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class SelectCityActivity extends BaseActivity {

    @BindView(R.id.iv_back_activity_basepersoninfo)
    ImageView mIvBackActivityBasepersoninfo;
    @BindView(R.id.tv_title_activity_baseperson)
    TextView mTvTitleActivityBaseperson;
    @BindView(R.id.tv_small_title_layout_head)
    TextView mTvSmallTitleLayoutHead;
    @BindView(R.id.rl_head_root_activity_baseperson)
    RelativeLayout mRlHeadRootActivityBaseperson;
    @BindView(R.id.iv_search_head)
    ImageView mIvSearchHead;
    @BindView(R.id.edit_search_head)
    EditText mEditSearchHead;
    @BindView(R.id.tv_location_city_activity_select_city)
    TextView mTvLocationCityActivitySelectCity;
    @BindView(R.id.recycler_view)
    RecyclerView mRecycleActivitySelectCity;
    private SelectCityRecyclewAdapter mSelectCityRecyclewAdapter;
    private List<CityBean> mCityBeans;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_select_city);
    }

    @Override
    protected void initData() {
        super.initData();

        mTvTitleActivityBaseperson.setText("选择城市");
        mRlHeadRootActivityBaseperson.setBackgroundColor(UIUtils.getColor(R.color.c_ffffffff));
        mCityBeans = new ArrayList<>();
        CityBean cityBean=new CityBean();
        cityBean.setCityName("成都市");
        cityBean.setSpell("c");
        mCityBeans.add(cityBean);

        mSelectCityRecyclewAdapter = new SelectCityRecyclewAdapter(this, mCityBeans);

        mRecycleActivitySelectCity.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

        mRecycleActivitySelectCity.addItemDecoration(new RecyclerViewCityDecoration(this, mCityBeans));

        mRecycleActivitySelectCity.setAdapter(mSelectCityRecyclewAdapter);
        mSelectCityRecyclewAdapter.setOnListener(new SelectCityRecyclewAdapter.OnListener() {
            @Override
            public void onItemClick(int positon) {
                EventBus.getDefault().post(new SelectHouseEvent(mCityBeans.get(positon).getCityName(),1));
                SelectCommunityActivity.myStartActivity(SelectCityActivity.this);

            }
        });
    }

    @OnClick(R.id.iv_back_activity_basepersoninfo)
    public void onMIvBackActivityBasepersoninfoClicked() {
        finish();
    }



public static void myStartActivity(Context context){
    Intent intent=new Intent(context,SelectCityActivity.class);
    context.startActivity(intent);

}
}
